package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbFlowCompVplPinAttr;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TbFlowCompVplPinAttrDao {
    @Select("<script>" +
            "select " +
            "* " +
            "from " + DB7TableName.TB_FLOW_COMP_VPL_PIN_ATTR + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    List<TbFlowCompVplPinAttr> getTbFlowCompVplPinAttrByFlowNo(@Param("flowNo") String flowNo,
                                                            @Param("flowLevel") Integer flowLevel);

    @Insert("<script>" +
            "insert into " + DB7TableName.TB_FLOW_COMP_VPL_PIN_ATTR + " " +
            "( "+
            "flow_no, " +
            "flow_level, " +
            "create_time, " +
            "create_user, " +
            "update_time, " +
            "update_user, " +
            "mpn, " +
            "pkg_name, " +
            "pin_min_pitch, " +
            "pin_count, " +
            "pin_number, " +
            "pin_x_v, " +
            "pin_y_v, " +
            "pin_length, " +
            "pin_width, " +
            "pin_length_tol_p, " +
            "pin_length_tol_n, " +
            "pin_width_tol_p, " +
            "pin_width_tol_n, " +
            "pin_type, " +
            "pin_high, " +
            "pin_high_tol_p, " +
            "pin_high_tol_n " +
            ")"+
            "values "+
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            "(" +
            "#{entity.flow_no}, " +
            "#{entity.flow_level}, " +
            "#{entity.create_time}, " +
            "#{entity.create_user}, " +
            "#{entity.update_time}, " +
            "#{entity.update_user}, " +
            "#{entity.mpn}, " +
            "#{entity.pkg_name}, " +
            "#{entity.pin_min_pitch}, " +
            "#{entity.pin_count}, " +
            "#{entity.pin_number}, " +
            "#{entity.pin_x_v}, " +
            "#{entity.pin_y_v}, " +
            "#{entity.pin_length}, " +
            "#{entity.pin_width}, " +
            "#{entity.pin_length_tol_p}, " +
            "#{entity.pin_length_tol_n}, " +
            "#{entity.pin_width_tol_p}, " +
            "#{entity.pin_width_tol_n}, " +
            "#{entity.pin_type}, " +
            "#{entity.pin_high}, " +
            "#{entity.pin_high_tol_p}, " +
            "#{entity.pin_high_tol_n} " +
            ")"+
            "</foreach>"+
            "</script>"
    )
    Integer insertTbFlowCompVplPinAttrBatch(@Param("entities") List<TbFlowCompVplPinAttr> entities);

    @Update("<script>" +
            "update " + DB7TableName.TB_FLOW_COMP_VPL_PIN_ATTR + " " +
            "set " +
            " <if test='entity.mpn != null'>mpn = #{entity.mpn},</if>" +
            " <if test='entity.pkg_name != null'>pkg_name = #{entity.pkg_name},</if>" +
            " <if test='entity.pin_min_pitch != null'>pin_min_pitch = #{entity.pin_min_pitch},</if>" +
            " <if test='entity.pin_count != null'>pin_count = #{entity.pin_count},</if>" +
            " <if test='entity.pin_number != null'>pin_number = #{entity.pin_number},</if>" +
            " <if test='entity.pin_x_v != null'>pin_x_v = #{entity.pin_x_v},</if>" +
            " <if test='entity.pin_y_v != null'>pin_y_v = #{entity.pin_y_v},</if>" +
            " <if test='entity.pin_length != null'>pin_length = #{entity.pin_length},</if>" +
            " <if test='entity.pin_width != null'>pin_width = #{entity.pin_width},</if>" +
            " <if test='entity.pin_length_tol_p != null'>pin_length_tol_p = #{entity.pin_length_tol_p},</if>" +
            " <if test='entity.pin_length_tol_n != null'>pin_length_tol_n = #{entity.pin_length_tol_n},</if>" +
            " <if test='entity.pin_width_tol_p != null'>pin_width_tol_p = #{entity.pin_width_tol_p},</if>" +
            " <if test='entity.pin_width_tol_n != null'>pin_width_tol_n = #{entity.pin_width_tol_n},</if>" +
            " <if test='entity.pin_type != null'>pin_type = #{entity.pin_type},</if>" +
            " <if test='entity.pin_high != null'>pin_high = #{entity.pin_high},</if>" +
            " <if test='entity.pin_high_tol_p != null'>pin_high_tol_p = #{entity.pin_high_tol_p},</if>" +
            " <if test='entity.pin_high_tol_n != null'>pin_high_tol_n = #{entity.pin_high_tol_n},</if>" +
            " update_time = #{entity.update_time}," +
            " update_user = #{entity.update_user}" +
            " where id = #{entity.id}" +
            //"where flow_no = #{entity.flow_no} and flow_level = #{entity.flow_level}" +
            "</script>"
    )
    Integer updateTbFlowCompVplPinAttr(@Param("entity") TbFlowCompVplPinAttr entity);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL_PIN_ATTR + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    Integer deleteTbFlowCompVplPinAttr(@Param("flowNo") String flowNo, @Param("flowLevel") Integer flowLevel);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL_PIN_ATTR + " " +
            "where flow_no = #{flowNo}" +
            "</script>"
    )
    Integer deleteTbFlowCompVplPinAttrByFlowNo(@Param("flowNo") String flowNo);
}
